package com.chzc.fm.duotin.ui.home;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.adapter.recyclerview.HomeAdapter;
import com.chzc.fm.duotin.bean.home.RecommendData;
import com.chzc.fm.duotin.bean.home.RecommendDataList;
import com.chzc.fm.duotin.ui.home.utils.JumpManager;
import com.chzc.fm.duotin.utils.ImageUtil;
import com.chzc.fm.duotin.utils.LogUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 * Created by Administrator on 2016/6/25.
 */
public class SpecialTopicPannel extends RelativeLayout{

  //  private LinearLayout llroot;
    private TextView tvType,tvMore,tvTitle,tvContent;
    private ImageView ivContent;
    //底部的专题列表
    private RecyclerView rvTopic;



    public SpecialTopicPannel(Context context, RecommendData data) {
        super(context);
        initView(context);
        setData(context,data);
    }

    public SpecialTopicPannel(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }


    private void initView(Context context) {
        inflate(context, R.layout.fragment_home_special_topic_pannel,this);
       // llroot = (LinearLayout) findViewById(R.id.llroot);
        tvType = (TextView) findViewById(R.id.tv_type);
        tvMore = (TextView) findViewById(R.id.tv_more);
        ivContent = (ImageView) findViewById(R.id.ivConent);
        tvTitle = (TextView) findViewById(R.id.tvTitle);
        tvContent = (TextView) findViewById(R.id.tv_content);



    }
    public void setData(Context context,RecommendData data){


        List<RecommendDataList> list = data.getData_list();
        if (list.size()==1) {
            final RecommendDataList datalist = data.getData_list().get(0);

            //绑定数据
            LogUtil.e("data" + data.getData_list().toString());
            tvType.setText(data.getColumn().getTitle());
            tvMore.setText(data.getColumn().getRedirect_words());
            //设置图片以及文字内容

            String imUlr = datalist.getImage_url();
            //ivContent.setScaleType(ImageView.ScaleType.FIT_XY);
          //  ViewGroup.MarginLayoutParams marginLayoutParams = (MarginLayoutParams) getLayoutParams();
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,350);
            ivContent.setLayoutParams(params);
            ImageLoader.getInstance().displayImage(imUlr, ivContent, ImageUtil.getRoundOptions());
            tvTitle.setText(datalist.getSub_title());
            tvContent.setText(datalist.getTitle());

            //设置跳转监听事件
            //
            ivContent.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    JumpManager.jumpTopicListView(getContext(),datalist.getItem_value());
                }
            });

            LogUtil.e("传递的ID"+datalist.getItem_value());


        }else{
            removeAllViews();
            inflate(context,R.layout.fragment_home_special_topic_pannel_more,this);
            //设置底部的列表
            rvTopic = (RecyclerView) findViewById(R.id.rv_topic);
            LinearLayoutManager manager = new LinearLayoutManager(getContext());
            rvTopic.setLayoutManager(manager);
            //设置适配器，及每一个item中需要显示的数据
            HomeAdapter adapter = new HomeAdapter(context,list);
            rvTopic.setAdapter(adapter);
        }

    }
}
